const util = require('../../utils/util')

Page({
  data: { //本页面的全局变量
    username: '',
    password: '',
  },

  onLoad(options) { //狭义理解的主函数
    if(wx.getStorageSync('uid')){
      wx.switchTab({
        url: '../index/index',
      })
    }
  },

  onInput(e) { //e指代当前的事件
    //console.log(e.detail.value) 获取内容
    //console.log(e.currentTarget.dataset.name) //获取标签的名字

    this.data[e.currentTarget.dataset.name] = e.detail.value  //this是本页面，调用data
  },
  submit() {
    console.log(this.data.username)
    console.log(this.data.password)
    wx.setStorageSync('username', this.data.username)
    util.http('/login/vx', this.data, resp=>{
      if(resp.code == 1){
        wx.setStorageSync('uid', resp.uid)
        wx.switchTab({
          url: '../index/index'
        })
      }else{
        util.alert(resp.msg)
      }
    })
  }
})